import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
} from 'typeorm';
import { MenuType } from '../menus.enum';

@Entity({ name: 'tb_menus' })
export class Menu {
  @PrimaryGeneratedColumn('increment', {
    name: 'menu_id',
    type: 'bigint',
    comment: '菜单ID 主键',
    primaryKeyConstraintName: 'menu_id',
  })
  menu_id: number;

  @Column({
    name: 'father_id',
    type: 'bigint',
    comment: '父菜单ID, 0表示根节点',
    default: 0,
  })
  father_id: number;

  @Column({
    name: 'menu_type',
    type: 'enum',
    enum: MenuType,
    default: MenuType.DIRECTORY,
    comment: '菜单类型，枚举，DIRECTORY-目录，MENU-菜单，BUTTON-按钮',
  })
  menu_type: string;

  @Column({
    name: 'menu_code',
    type: 'varchar',
    length: 255,
    unique: true,
    nullable: true,
    comment: '菜单/目录/按钮CODE，唯一标识',
  })
  menu_code: string;

  @Column({
    name: 'menu_name',
    type: 'varchar',
    length: 255,
    nullable: true,
    comment: '菜单/目录/按钮名称',
  })
  menu_name: string;

  @Column({
    name: 'menu_icon',
    type: 'varchar',
    length: 255,
    nullable: true,
    comment: '菜单/目录/按钮图标',
  })
  menu_icon: string;

  @Column({
    name: 'menu_route',
    type: 'varchar',
    length: 255,
    nullable: true,
    comment: '菜单/目录路由',
  })
  menu_route: string;

  @Column({
    name: 'menu_views',
    type: 'varchar',
    length: 255,
    nullable: true,
    comment: '菜单组件路径',
  })
  menu_views: string;

  @Column({
    name: 'menu_sort',
    type: 'int',
    nullable: true,
    comment: '菜单/目录/按钮位置排序',
  })
  menu_sort: number;

  @Column({
    name: 'displayed',
    type: 'tinyint',
    default: false,
    comment: '菜单是否展示，1-是，0-否，默认否',
  })
  displayed: number;

  @Column({
    name: 'description',
    type: 'text',
    nullable: true,
    comment: '菜单/目录/按钮描述信息',
  })
  description: string;

  @Column({
    name: 'extend',
    type: 'text',
    nullable: true,
    comment: '菜单/目录/按钮扩展信息',
  })
  extend: string;

  @UpdateDateColumn({
    name: 'updated_at',
    type: 'timestamp',
    comment: '最后一次更新时间',
  })
  updated_at: number;

  @CreateDateColumn({
    name: 'created_at',
    type: 'timestamp',
    comment: '创建时间',
  })
  created_at: number;
}
